//
//  UCViewConvertible.swift
//  Pods-UICreate_Example
//
//  Created by JY_NEW on 2022/1/17.
//

import UIKit

public protocol UCViewConvertible: UCBuildable {
    associatedtype UCViewType: UIView
    func asView() -> UCViewType
}
extension UCViewConvertible {
    public func asView(_ settings: UCSetting<UCViewType>...) -> UCViewType {
        let view = self.asView()
        view.set(animated: 0, settings: settings)
        return view
    }
    public func __uiCreatePerformBuild(add: (UIView) -> Void) {
        self.asView().__uiCreatePerformBuild(add: add)
    }
    public func __uiCreatePerformBuildLayout() {
        self.asView().__uiCreatePerformBuildLayout()
    }
}
extension String: UCViewConvertible {
    public typealias UCViewType = UILabel
    public func asView() -> UCViewType {
        return .init(.text(self))
    }
}
extension UIImage: UCViewConvertible {
    public typealias UCViewType = UIImageView
    public func asView() -> UCViewType {
        return .init(.image(self), .content(mode: .scaleToFill))
    }
}
extension Date: UCViewConvertible {
    public typealias UCViewType = UIDatePicker
    public func asView() -> UCViewType {
        return .init(.date(self))
    }
}
